package mysql

import "time"

type Order struct {
	OrderId         int64
	UserId          int64
	OrderDate       time.Time
	OrderStatus     string
	ShippingAddress string
	TotalAmount     string
}

func WhereOrder(OrderId int64) Order {
	var order Order
	db.Model(&Order{}).Where("order_id = ?", OrderId).First(&order)
	return order
}

func SavePaymentStatus(order Order) error {
	tx := db.Begin()
	err := tx.Model(&Order{}).Where("order_id = ?", order.OrderId).Save(&order).Error
	if err != nil {
		tx.Rollback()

	}
	tx.Commit()
	return err
}

func CreateOrder(order Order) (Order, error) {
	tx := db.Begin()
	err := tx.Model(&Order{}).Create(order).Error
	if err != nil {
		tx.Rollback()

	}
	tx.Commit()
	return order, err
}
